package com.snail.billing.json;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class JsonWorkType extends JsonBase {

	private List<Type> types;

	public JsonWorkType(String jsonString) {
		super(jsonString);
		try {
			if (getCode() == 1) {
				types = new ArrayList<Type>();
				JSONArray jsonArray = new JSONObject(jsonString).getJSONArray("data");
				for (int i = 0; i < jsonArray.length(); i++) {
					Type type = new Type(jsonArray.getString(i));
					types.add(type);
				}
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
	}

	public List<Type> getTypes() {
		return types;
	}

	public class Type {
		private String parentName;
		private String parentCode;
		private String name;
		private String code;

		public Type(String jsonString) {
			try {
				JSONObject json = new JSONObject(jsonString);
				if (json.has("PARENT_NAME")) {
					parentName = json.getString("PARENT_NAME");
				}
				if (json.has("S_PARENT_CODE")) {
					parentCode = json.getString("S_PARENT_CODE").substring(1);
				}
				if (json.has("S_ISSURE_NAME")) {
					name = json.getString("S_ISSURE_NAME");
				}
				if (json.has("S_CODE")) {
					code = json.getString("S_CODE");
				}
			} catch (JSONException e) {
				e.printStackTrace();
			}
		}

		public String getParentName() {
			return parentName;
		}

		public String getParentCode() {
			return parentCode;
		}

		public String getName() {
			return name;
		}

		public String getCode() {
			return code;
		}
	}

}
